<?php
namespace app\index\controller;

use app\BaseController;
use think\facade\Db;
use think\facade\Request;

class Navigation extends Base
{
     public function yanshi()
    {
        $id=input('id');
        $typeData1=Db::name('navigationtype')->where('parentid',1)->where('id',$id)->select();
           $navigationData=Db::name('navigation')->select();
            foreach ($typeData1 as $k=>$val){
    $cate1[$k]['id'] = $typeData1[$k]['id'];
    $cate1[$k]['status'] = $typeData1[$k]['status'];
    $cate1[$k]['name'] = $typeData1[$k]['name'];
      foreach ($navigationData as $item){
        if ($item['cate_id'] == $val['id']){
        $cate1[$k]['app'][] = $item;
        }
      }
     }
 
        return view('',[
    'typeData1'=>$typeData1,
     'cate1'=>$cate1,
        ]);
    }
    
    public function index()
    {
    
//   $typeData1=Db::name('navigationtype')->where('parentid',1)->select();

   $navigationData=Db::name('navigation')->select();
   $typeData2=Db::name('navigationtype')->where('parentid',2)->select();
   $typeData3=Db::name('navigationtype')->where('parentid',3)->select();
    //  foreach ($typeData1 as $k=>$val){
    // $cate1[$k]['id'] = $typeData1[$k]['id'];
    // $cate1[$k]['status'] = $typeData1[$k]['status'];
    // $cate1[$k]['name'] = $typeData1[$k]['name'];
    //   foreach ($navigationData as $item){
    //     if ($item['cate_id'] == $val['id']){
    //     $cate1[$k]['app'][] = $item;
    //     }
    //   }
    //  }
 foreach ($typeData2 as $k=>$val){
    $cate2[$k]['id'] = $typeData2[$k]['id'];
    $cate2[$k]['status'] = $typeData2[$k]['status'];
    $cate2[$k]['name'] = $typeData2[$k]['name'];
       foreach ($navigationData as $item){
        if ($item['cate_id'] == $val['id']){
        $cate2[$k]['app'][] = $item;
        }
       }
     }
   foreach ($typeData3 as $k=>$val){
    $cate3[$k]['id'] = $typeData3[$k]['id'];
    $cate3[$k]['status'] = $typeData3[$k]['status'];
    $cate3[$k]['name'] = $typeData3[$k]['name'];
       foreach ($navigationData as $item){
        if ($item['cate_id'] == $val['id']){
        $cate3[$k]['app'][] = $item;
        }
       }
     }
   

   
   
//   foreach ($toptypeData as $k=>$val){
//   $typeDatas[$k]['id'] = $toptypeData[$k]['id'];
//   $typeDatas[$k]['topname'] = $toptypeData[$k]['topname'];
//   foreach ($typeData as $item){
//   if ($item['parentid'] == $val['id']){

//   $typeDatas[$k]['name'][] = $item;
//   }
 
//   }
 
//   }
//   foreach ( $typeDatas[$k]['name'] as $ks=>$vals){
      
//   foreach ($navigationData as $app){
//   if ($app['cate_id'] == $vals['id']){

//   $typeDatas[$k]['name'][$ks]['neirong'][] = $app;
//   }
 
//   }
 
//   }

      return view('',[
    // 'typeData1'=>$typeData1,
     'navigationData'=>$navigationData,
    //  'cate1'=>$cate1,
     'cate2'=>$cate2,
     'cate3'=>$cate3,
        ]);
    }

 
    public function action(){
        $id=input('id');
    $apiData=Db::name('api')->find($id);
    $returnParameters=json_decode($apiData['returnParameters'], true);
    $RequestParameters=json_decode($apiData['RequestParameters'], true);
    $errorcode=json_decode($apiData['errorcode'], true);
    $systemcode=json_decode($apiData['systemcode'], true);
      return view('',[
     'apiData'=>$apiData,
     'RequestParameters'=>$RequestParameters,
     'returnParameters'=>$returnParameters,
     'errorcode'=>$errorcode,
     'systemcode'=>$systemcode,
        ]);
    }



    public function list(){
        $id=input('id');

       $categoryData=Db::name('category')->find($id);
       $archivesData=Db::name('archives')->field('id,time,title')->where('cate_id',$id)->paginate(20);
       //print_r($archivesData);
        return view('',[
            'categoryData'=>$categoryData,
            'archivesData'=>$archivesData,
            'menu_id'=>$id
        ]);
    }
  
  public function productlist(){
       $id=input('cate_id');
       $typeData=Db::name('category')->select();
       $archivesData=Db::name('archives')->where('cate_id',$id)-> paginate([
              'list_rows'=> 20,//每页数量
              'query' => request()->param(),
              ]);
            
        return view('',[
            'archivesData'=>$archivesData,
            'typeData'=>$typeData,
            'menu_id'=>7
        ]);
    }
    public function contact(){
        $id=7;
        $categoryData=Db::name('category')->find($id);
        return view('',[
            'categoryData'=>$categoryData,
            'menu_id'=>7
        ]);
    }

    public function article(){
        $id=input('id');

       $archivesData=Db::name('archives')->find($id);
       $categoryData=Db::name('category')->find($archivesData['cate_id']);

        return view('',[
            'categoryData'=>$categoryData,
            'archivesData'=>$archivesData,
            'menu_id'=>$id
        ]);
    }

  
}
